package com.jeesite.modules.jydq.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.jydq.entity.JydqPlatform;
import com.jeesite.modules.jydq.service.JydqPlatformService;

/**
 * 电商平台信息表Controller
 * @author dong
 * @version 2025-03-20
 */
@Controller
@RequestMapping(value = "${adminPath}/jydq/platform")
public class JydqPlatformController extends BaseController {

	@Autowired
	private JydqPlatformService jydqPlatformService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public JydqPlatform get(String id, boolean isNewRecord) {
		return jydqPlatformService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
//	@RequiresPermissions("jydq:platform:view")
	@RequestMapping(value = {"list", ""})
	public String list(JydqPlatform jydqPlatform, Model model) {
		model.addAttribute("jydqPlatform", jydqPlatform);
		return "modules/jydq/jydqPlatformList";
	}
	
	/**
	 * 查询列表数据
	 */
//	@RequiresPermissions("jydq:platform:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<JydqPlatform> listData(JydqPlatform jydqPlatform, HttpServletRequest request, HttpServletResponse response) {
		jydqPlatform.setPage(new Page<>(request, response));
		Page<JydqPlatform> page = jydqPlatformService.findPage(jydqPlatform);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
//	@RequiresPermissions("jydq:platform:view")
	@RequestMapping(value = "form")
	public String form(JydqPlatform jydqPlatform, Model model) {
		model.addAttribute("jydqPlatform", jydqPlatform);
		return "modules/jydq/jydqPlatformForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("jydq:platform:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated JydqPlatform jydqPlatform) {
		jydqPlatformService.save(jydqPlatform);
		return renderResult(Global.TRUE, text("保存电商平台信息表成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("jydq:platform:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(JydqPlatform jydqPlatform) {
		jydqPlatformService.delete(jydqPlatform);
		return renderResult(Global.TRUE, text("删除电商平台信息表成功！"));
	}

	/**
	 * 查询下拉框选项
	 */
	@RequestMapping({"treeData"})
	@ResponseBody
	public List<Map<String, Object>> treeData(JydqPlatform jydqPlatform) {
		List<Map<String, Object>> list = new ArrayList<>();
		List<JydqPlatform> list1 = jydqPlatformService.findList(jydqPlatform);
		for (JydqPlatform data : list1) {
			HashMap<String, Object> map = new HashMap<>();
			map.put("id",data.getId());
			map.put("name",data.getName());
			list.add(map);
		}
		return list;
	}
	
}